package com.demo.queue;

import org.apache.commons.math3.analysis.function.Add;

import java.util.LinkedList;
import java.util.function.Consumer;

/**
 * @author libo
 * @version 1.0
 * @date 2018/5/4 16:09
 */
public class AysnQueued {

    private final LinkedList linkedList = new LinkedList();
    Thread thread;

    public void add(Object o){
        synchronized (linkedList) {
            linkedList.addLast(o);
        }
        if(thread == null) {
            thread = new Thread(()->{
                synchronized (linkedList) {
                    while (!linkedList.isEmpty()) {
                        Object poll = linkedList.poll();
                        System.out.println(poll);
                    }
                }
            });
            thread.start();
        }
    }
}
